<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	template="/layout/template.xhtml">


	<ui:define name="body">


		<a4j:form id="pecaForm">
			<p:messages globalOnly="true" styleClass="message" />
			<rich:simpleTogglePanel switchType="client">
				<f:facet name="header">Peças</f:facet>
				<div style="clear: both" />



				<s:decorate id="descricaoField" template="/layout/edit.xhtml">
					<ui:define name="label">Descricao:</ui:define>
					<h:inputText id="descricao" size="60" value="#{peca.descricao}"
						required="true">
						<a4j:support event="onblur" reRender="descricaoField"
							bypassUpdates="true" ajaxSingle="true" status="none"/>
					</h:inputText>
				</s:decorate>

				<s:decorate id="valorField" template="/layout/edit.xhtml">
					<ui:define name="label">Valor:</ui:define>
					<h:inputText id="valor" size="10" value="#{peca.valor}"
						required="true">
						<a4j:support event="onblur" reRender="valorField"
							bypassUpdates="true" ajaxSingle="true" status="none"/>
					</h:inputText>
				</s:decorate>


				<br />
				<br />
				<div style="clear: both"><span class="required">*</span>
				Campos requeridos</div>

				<div style="clear: both" />
				<br />
				<br />

				<div class="actionButtons">
				
				
					<a4j:commandButton value="Inserir" style=" width : 100px;"
						action="#{pecaAction.salvar(peca)}" rendered="#{peca.id == null}"
						reRender="pecaForm, frmTabelaPeca" />
				
				<a4j:commandButton value="Editar" style=" width : 100px;"
					action="#{pecaAction.alterar(peca)}" rendered="#{peca.id != null}"
					reRender="pecaForm, frmTabelaPeca" /> <a4j:commandButton
					value="#{messages['btnCancel']}" style="width : 100px;"
					action="#{pecaAction.cancelar()}" rendered="#{peca.id != null}"
					reRender="pecaForm" ajaxSingle="true" /></div>




			</rich:simpleTogglePanel>
		</a4j:form>

		<rich:spacer width="5px" />
		<br />
		<br />

		<a4j:form id="frmTabelaPeca">

			<rich:dataTable value="#{pecaAction.carregarTodos()}" var="peca"
				rows="10" reRender="ds" id="simpletable"
				rendered="#{pecaAction.carregarTodos().size > 0}"
				columnClasses="center"
				onRowMouseOver="this.style.backgroundColor='#b2d5d6'"
				onRowMouseOut="this.style.backgroundColor='#FFFFFF'">
				<f:facet name="header">
					<h:outputText value="Peças" />
				</f:facet>
				<rich:column sortBy="#{peca.descricao}">
					<f:facet name="header">
						<h:outputText value="Descrição" />
					</f:facet>
					<h:outputText value="#{peca.descricao}" />
				</rich:column>

				<rich:column sortBy="#{peca.valor}">
					<f:facet name="header">
						<h:outputText value="Valor" />
					</f:facet>
					<h:outputText value="#{peca.valor}">
					<f:convertNumber pattern="#,##0.00" />
					</h:outputText>
				</rich:column>

				<rich:column style="text-align: center;">
					<f:facet name="header">
						<h:outputText value="Editar" />
					</f:facet>
					<a4j:commandLink action="#{pecaAction.selecionarPeca(peca)}"
						reRender="pecaForm">
						<h:graphicImage value="/img/ico_altera_16.gif"
							style="border: none;" alt="Alterar" title="Alterar Registro" />
					</a4j:commandLink>
				</rich:column>
				<rich:column style="text-align: center;">
					<f:facet name="header">
						<h:outputText value="Apagar" />
					</f:facet>
					<a4j:commandLink action="#{pecaAction.excluir(peca)}"
						reRender="simpletable,pecaForm"
						onclick="if(!confirm('Confirma Exclus&#227;o?')){return false;}">
						<h:graphicImage value="/img/ico_apaga_16.gif"
							style="border: none;" alt="Excluir" title="Excluir Registro" />
					</a4j:commandLink>
				</rich:column>


				<f:facet name="footer">
					<rich:datascroller id="ds"></rich:datascroller>
				</f:facet>
			</rich:dataTable>



		</a4j:form>



	</ui:define>

</ui:composition>